<?php
function AliyunOSS_RemoteImage_Save($rurl,$file_path,$file_name,$object) {
    global $zbp,$obj,$bucket;

    ob_start();
    readfile($rurl);
    $img = ob_get_contents();

    if($zbp->Config('AliyunOSS')->water_enable) {
        $waterImage=$zbp->path . 'zb_users/plugin/AliyunOSS/img/watermark.png'; //作为水印的图片，暂只支持GIF,JPG,PNG格式；
        $waterPos =$zbp->Config('AliyunOSS')->waterPos; //水印位置
        $waterText=$zbp->Config('AliyunOSS')->waterText;//文字水印，即把文字作为为水印；
        $textFont =$zbp->Config('AliyunOSS')->textFont;//文字大小；
        $textColor=$zbp->Config('AliyunOSS')->textColor;//文字颜色，值为十六进制颜色值，默认为#FF0000(红色)；
        $watermarkType=$zbp->Config('AliyunOSS')->watermarkType;
        $tmp_info = getimagesize($img);
        if($tmp_info[2]>0 and  $tmp_info[2]<4) {
            AliyunOSS_Watermark_Do($tmp,$waterPos,$waterImage,$waterText,$textFont,$textColor,$watermarkType);
        }
    }

    ob_end_clean();
    $size = strlen($img);

    $fp2=@fopen($file_path, "a");
    fwrite($fp2,$img);
    fclose($fp2);

    $response = $obj->upload_file_by_file($bucket,$object,$file_path);//将本地文件上传到云

    $upload = new Upload;
    $upload->Name = $file_name;
    $upload->SourceName = $file_name;
    $upload->MimeType = '';
    $upload->Size = $size;
    $upload->AuthorID = $zbp->user->ID;
    $upload->Metas->AliyunOSS_URL = $object;
    $upload->Save();
    
    unlink($file_path);

    return true; 

}